using System;
using Arcane.Source.Client;
using Arcane.Source.Data;
using Godot;

namespace Arcane.Source.MainMenu
{
    public partial class MainMenuView : Control, IView
    {
        [Export]
        Control _logo;

        public Color? ClearColor { get; init; } = new Color(0x639bffff);

        public Control UI => this;
        public Node Node => null;
        public GameOS Os { get; set; }

        public event Action RequestStart;

        private double _timer;
        private const double SixTau = 6.0 * double.Tau;

        private Control _infoDialog;


        public override void _Ready()
        {
            if (Os == null) return;

            _infoDialog = new DialogBuilder()
                .WithTitle("Project: Arcane")
                .WithMessage("QQ Channel: pd22719681")
                .WithMessage("Copyright @Zerous Studio")
                .AddButton("Ok", Os.HideAlert)
                .Build(new Color(0x333333ff));
        }

        public override void _Process(double delta)
        {
            _logo?.Set(StringNames.OFFSET, 0.0125 * Mathf.Sin(1.5 * _timer) + 0.0625);

            _timer += delta;
            if (_timer > SixTau)
            {
                _timer = 0;
            }
        }

        private void OnStart()
        {
            RequestStart?.Invoke();
        }

        private void RequestExit()
        {
            Os.PopContext();
        }

        private void ShowInfo()
        {
            Os.ShowAlert(_infoDialog);
        }
    }
}